﻿using System;
using System.Windows;
using GC_VKMD.MusicDownloaderClient.Abstractions.Interfaces;
using GC_VKMD.MusicDownloaderClient.Enums;

namespace GC_VKMD.MusicDownloaderClient.Abstractions
{
	public abstract class WindowBaseAdapter : IWindow
	{
		#region Variables

		private readonly Window _wpfWindow;

		#endregion

		#region Protected Properties

		protected bool IsWpfWindowInitialized { get; set; }

		protected Window WpfWindow
		{
			get { return _wpfWindow; }
		}

		#endregion

		#region Constructors

		protected WindowBaseAdapter(Window wpfWindow)
		{
			if (wpfWindow == null)
				throw new ArgumentNullException(string.Format("wpfWindow"));
			_wpfWindow = wpfWindow;

			WindowDialogStatus = WindowDialogStatus.Cancel;
		}

		#endregion

		#region IWindow Members

		public WindowDialogStatus WindowDialogStatus { get; set; }

		public virtual void Close()
		{
			EnsureInitialized();
			WindowDialogStatus = WindowDialogStatus.Cancel;
			_wpfWindow.Close();
		}

		public void Close(WindowDialogStatus windowDialogStatus)
		{
			EnsureInitialized();
			WindowDialogStatus = windowDialogStatus;
			_wpfWindow.Close();
		}

		public virtual void Show()
		{
			EnsureInitialized();
			_wpfWindow.Show();
		}

		public virtual bool? ShowDialog()
		{
			EnsureInitialized();
			return _wpfWindow.ShowDialog();
		}

		#endregion

		#region Abstract Methods

		protected abstract void EnsureInitialized();

		#endregion
	}
}
